<?php
namespace app\api\controller;

use app\api\model\TrainModel;
use think\Controller;

class Train extends Controller
{
     function  trainlist(){
         $model=new  TrainModel();
         $result = $model->trainlist();
         return json($result);
     }
    function traindetail(){
        $traindetail=input('get.trainid');
        $model=new  TrainModel();
        $result = $model->traindetail($traindetail);
        if ($result){
            return json($result);
        }
    }
    function posttrain(){
        $userid=input('get.userid');
        $sessionid=input('get.sessionid');
        $trainid=input('get.trainid');
        $redis = getRedis();
       if ($sessionid&&$sessionid==$redis->get($userid)){
           $model=new  TrainModel();
           $result = $model->posttrain($userid,$trainid);
           if ($result==1)
           {
               return  json("你已经报过此培训了");
           }
           else if ($result==2)
           {
               return  json(['success'=>1]);
           }
           else if ($result==3)
           {
               return  json("报名失败");
           }
       }
       else{
           return  json(['error'=>"登录错误"]);
       }
    }

}